<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="${pageContext.request.contextPath }/public/plugin/layui/css/layui.css">
		<link rel="stylesheet" href="${pageContext.request.contextPath }/public/plugin/validform/css/style.css">
		<script type="text/javascript" src="${pageContext.request.contextPath }/public/plugin/jquery/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/public/plugin/artDialog/jquery.artDialog.js?skin=blue"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/public/plugin/artDialog/plugins/iframeTools.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/public/plugin/validform/Validform_v5.3.2_min.js"></script>
		
		<link rel="stylesheet" href="${pageContext.request.contextPath }/public/plugin/ztree/css/zTreeStyle/zTreeStyle.css">
		<script type="text/javascript" src="${pageContext.request.contextPath }/public/plugin/ztree/js/jquery.ztree.all.min.js"></script>
	
	
	   <script type="text/javascript">
		   var zTreeObj;
		   // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
		   var setting = {
			   check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "pId",
						rootPId: 0
					}
				}
		    };
		   // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
		   var zNodes;
		   
		   $(document).ready(function(){
			   $.post("${pageContext.request.contextPath }/admin/role/getRoleMenus",{roleId:"${m.id}"},function(resultObj){
				   zNodes=resultObj;
				   zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			    });
		     
		   });
	   </script>
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" style="margin-bottom: 10px;">
				<span class="layui-breadcrumb">
				  <a href="">系统配置</a>
				  <a href=""><cite>角色管理</cite></a>
				</span>
			</div>

			<form class="layui-form registerform" action="${pageContext.request.contextPath }/admin/user/saveOrUpdate">
			   　　<input type="hidden" name="isUpdate" value="${isUpdate }">
			     <input type="hidden" name="id" value="${m.id }"> 
			
				<div class="layui-form-item">
					<label class="layui-form-label">角色名称</label>
					<div class="layui-input-block" style="line-height: 40px;">
						${m.name }
						<div class="Validform_checktip"></div>
					</div>
				</div>

			
				
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-block">
							 <ul id="treeDemo" class="ztree"></ul>
					</div>
				</div>
	
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" id="btn_sub" type="button" onclick="saveRoleMenus()" >立即提交</button>
						<button type="button" onclick="closeWin()" class="layui-btn layui-btn-primary">关闭</button>
					</div>
				</div>
			</form>

			
		</div>
		<script src="${pageContext.request.contextPath }/public/plugin/layui/layui.all.js"></script>
		<script type="text/javascript">
			//关闭窗口
			function closeWin(){
				art.dialog.close();
			}
			

			//保存方法
			function saveRoleMenus(){
				 var changgeNodes=zTreeObj.getCheckedNodes(true);
				 var idsMenusArray=new Array();
				 for(var i=0;i<changgeNodes.length;i++){
					 idsMenusArray.push(changgeNodes[i].id);
				 }

				var ids= idsMenusArray.join(",");
				$.post("${pageContext.request.contextPath }/admin/role/saveRoleMenus",{menusId:ids,roleId:"${m.id}"},function(resultObj){
					if(resultObj.status==1){
						alert(resultObj.msg);
						art.dialog.close();
				    }else{
						alert(resultObj.msg);
					}
				});
			}

		</script>
	</body>

</html>